<?php
/**
 * Created by PhpStorm.
 * User: liyu
 * Date: 2018/4/8
 * Time: 上午10:27
 */

namespace app\api\controller\v1;



use app\api\service\UserService;
use app\api\validate\UserValidate;
use think\Request;

class User extends UserAuth
{
    public function login()
    {
        (new UserValidate())->goCheck('login');
        $data = Request::instance()->only(['login_name', 'password']);
        $result = (new UserService())->login($data);
        return $this->showJsonReturnCode($result);
    }

    public function addInfo()
    {
        (new UserValidate())->goCheck('add');
        $data = Request::instance()->only(['login_name', 'name', 'password', 'org_id', 'enabled', 'gender', 'birthday', 'id_card_number', 'tel']);
        (new UserService())->addInfo($this->guid,$data);
        return $this->showJsonReturnCode();
    }

    public function updateInfo()
    {
        (new UserValidate())->goCheck('update');
        $data = Request::instance()->only(['login_name', 'name', 'password', 'org_id', 'gender', 'birthday', 'id_card_number', 'tel']);
        $where = Request::instance()->only(['guid']);
        (new UserService())->updateInfo($this->guid,$data,$where);
        return $this->showJsonReturnCode();
    }

    public function getListInfo()
    {
//        (new UserValidate())->goCheck('getList');
        $where = Request::instance()->only(['guid','login_name','name','org_id','enabled','tel']);
        $page = input('page');
        $result = (new UserService())->getUserInfoListByMap($where,$page);
        return $this->showJsonReturnCode($result);
    }

    public function getSelfInfo()
    {
        (new UserValidate())->goCheck('getMyInfo');
        $where = Request::instance()->only(['guid']);
        $result = (new UserService())->getUserInfo($where);
        return $this->showJsonReturnCode($result);
    }
}